﻿using System;
using System.Windows.Forms;
using ABMath;
using ABMath.ModelFramework.Models;
using CronosII;

namespace ExamplePlugin
{
    [CronosPlugin("Extra Models", CronosPluginType.Model)]
    public class ExtraModels : IPlugin
    {
        private IShell shell;

        public void Initialize(ToolStripDropDown dropDown, IShell parent)
        {
            shell = parent;

            var button1 = new ToolStripButton("Adaptive AR(1)");  // can give image as 2nd param too, if desired
            button1.Click += MenuCall;

            var button2 = new ToolStripButton("Switching AR(1)");
            button2.Click += MenuCall2;

            var button3 = new ToolStripButton("ACF Model");
            button3.Click += MenuCall3;

            var subMenu = new ToolStripMenuItem("Plugin Examples");
            subMenu.DropDownItems.AddRange(new ToolStripItem[] {button1, button2, button3});

            dropDown.Items.Add(subMenu);

            dropDown.AutoSize = false;
            dropDown.AutoSize = true;  // hack to force it to resize with the new item included
        }

        public void MenuCall(object e, EventArgs ea)
        {
            shell.DropIntoWorkspace(new AdaptiveARModel());
        }

        public void MenuCall2(object e, EventArgs ea)
        {
            shell.DropIntoWorkspace(new SwitchingARMAModel());
        }

        public void MenuCall3(object e, EventArgs ea)
        {
            var osf = new OrderSelectForm(1, "Number of Non-Zero Correlations");
            if (osf.ShowDialog() == DialogResult.OK)
            {
                shell.DropIntoWorkspace(new ACFModel(osf.AROrder));
            }
        }
    }
}

